<template>
  <div class="student">
    <h2>学生名字:{{ name }}</h2>
    <h2>学生年龄:{{ age }}</h2>
  </div>
</template>

<script>
//暴露组件
export default {
  name: 'Student',
  //data一定要写成函数
  data() {
    return {
      name: '张三',
      age: 18,
    };
  },
  mounted() {
    this.$bus.$on('getSchoolName', data => {
      console.log('收到了学校名称:', data);
    });
  },
  // 当Student组件销毁之前把事件解绑
  beforeDestroy() {
    this.$bus.off('getSchoolName');
  },
};
</script>

<style scoped>
.student {
  background-color: blue;
}
</style>
